using UnityEngine;
using System.Collections;

public class ProjectorColorSwapper : MonoBehaviour {
 
    public Projector target;
    public Material defaultMat;
    public Texture newTexture;
    
	// Use this for initialization
	void Start () {
	    if(target == null)
        {
            target = this.gameObject.GetComponent<Projector>();
        }
        if(defaultMat == null)
        {
            defaultMat = target.material;   
        }
	}
	
    public void SetColor(Color c)
    {
        Material tempMat = new Material(target.material);
        tempMat.SetColor("_Color", c);
        target.material = tempMat;
    }
    
    [ContextMenu("Red")]
    public void SetToRed()
    {
        if(target == null)
        {
            target = this.gameObject.GetComponent<Projector>();
        }
        Material tempMat = new Material(target.material);
        tempMat.SetColor("_Color", Color.red);
        target.material = tempMat;   
    }
 
    [ContextMenu("White")]
    public void SetToWhite()
    {
        if(target == null)
        {
            target = this.gameObject.GetComponent<Projector>();
        }
        Material tempMat = new Material(target.material);
        tempMat.SetColor("_Color", Color.white);
        target.material = tempMat;   
    }
    
    [ContextMenu("Reset Material")]
    public void ResetMaterial()
    {
        target.material = defaultMat;    
    }
    
    public void SetTexture(Texture t)
    {
        Material tempMat = new Material(target.material);
        tempMat.SetTexture("_ShadowTex", t);
        target.material = tempMat;
    }
    
    [ContextMenu("New Texture")]
    public void SetTextureToNewTexture()
    {
        if(newTexture == null) return;
        Material tempMat = new Material(target.material);
        tempMat.SetTexture("_ShadowTex", newTexture);
        target.material = tempMat;
    }
}
